package com.tushen.controller;

import com.tushen.service.CommonService;
import com.tushen.task.NC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by likun on 2020/8/2.
 */
@Controller
public class AppController {
    @Autowired
    private CommonService commonService;

    /**
     * 根据任意sql语句查询
     * @param sql
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "data/getbysql",produces = "application/json;charset=utf-8")
    public Map getTableBysql2(@RequestParam("sql") String sql){
        return commonService.getDataBySql(sql);

    }


    @ResponseBody
    @RequestMapping(value = "data/get_version_dtm",produces = "application/json;charset=utf-8")
    public Map getUVDtm(@RequestParam("version") String version,@RequestParam("type") String type){

        HashMap where = new HashMap();
        where.put("path", "get_version_dtm");
        where.put("version", version);
        where.put("type", type);
        return commonService.getQueryData(where, "commonQuery");
    }

    /**
     * 获取数据接口
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "data/process/{path}", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    public Map task(@RequestBody HashMap paramJson, @PathVariable("path") String path) {
        HashMap where = new HashMap();
        where.putAll(paramJson);
        where.put("path", path);
        return commonService.processData(where, "commonQuery");
    }

    @ResponseBody
    @RequestMapping(value = "data/query/{path}",produces = "application/json;charset=utf-8")
    public Map getQueryData(@RequestBody HashMap paramJson, @PathVariable("path") String path){

        HashMap where = new HashMap();
        where.putAll(paramJson);
        where.put("path",path);
        return commonService.getQueryData(where, "commonQuery");
    }




}
